# 封装函数实现文件拷贝
'''
@author:杰哥
@time:2021/10/28
@:param:
    old_file:原文件路径
    new_file:新文件路径
@return: 无
'''


def copy_file(old_file, new_file):
    fp1 = open(old_file, "rb")
    fp2 = open(new_file, "wb")
    # 将old_file文件中的内容写入到new_file中去
    fp2.write(fp1.read())
    fp2.flush()
    fp1.close()
    fp2.close()


copy_file("1单例设计模式.py", "拷贝单例设计模式.py")


# 拷贝视频等大文件
def copy_big_file(path1, path2):
    '''
    :param path1: 原文件路径
    :param path2: 新文件路径
    :return:  无
    '''
    fp1 = open(path1, "rb")
    fp2 = open(path2, "ab")  # a表示append向文件的尾部追加内容
    # 死循环
    while True:
        content = fp1.read(1024)
        if not content:
            print("拷贝完成")
            break
        fp2.write(content)
    fp1.close()
    fp2.flush()
    fp2.close()


copy_big_file(
    r"C:\python06\day14\视频\昨日作业.mp4",
    r"C:\python06\day14\昨日作业----2.mp4",
)
